<template>
  <!--  质检记录-->
  <div class="content">
    <el-tabs
        v-model="activeName"
        type="border-card"
        class="demo-tabs"
        @tab-click="handleClick"
        style="width: 100%"
    >
      <el-tab-pane label="工厂" name="first"></el-tab-pane>
      <el-tab-pane label="车间" name="second"></el-tab-pane>
      <el-tab-pane label="产品" name="third"></el-tab-pane>
      <el-form :inline="true" :model="searchParam">
        <!--				v-if="activeName==='first'"-->
        <el-form-item label="工厂">
          <el-select v-model="searchParam.factoryId" placeholder="请选择工厂" clearable filterable
                     style="width: 201px">
            <el-option v-for="item in factoryList" :key="item.id" :label="item.orgName" :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item label="车间" v-if="activeName === 'second'">
          <el-select v-model="searchParam.organizationIds" placeholder="请选择车间" clearable multiple style="width: 300px">
            <el-option v-for="item in workShopList" :key="item.id" :label="item.orgName" :value="item.id"/>
          </el-select>
        </el-form-item>
        <!--				<el-form-item label="车间" v-if="activeName === 'third'">-->
        <!--					<el-select v-model="searchParam.organizationId" placeholder="请选择车间" clearable style="width: 201px">-->
        <!--						<el-option v-for="item in workShopList" :key="item.id" :label="item.orgName" :value="item.id" />-->
        <!--					</el-select>-->
        <!--				</el-form-item>-->
        <el-form-item label="产品" v-if="activeName ==='third'">
          <el-select v-model="searchParam.materialId" placeholder="请输入产品编码" style="width:300px" clearable remote
                     :remote-method="getMaterialList" filterable>
            <el-option v-for="item in materialList" :key="item.id" :label="item.materialName"
                       :value="item.id"></el-option>
          </el-select>
          <!--					<el-input v-model="searchParam.materialNo" placeholder="请输入产品编号" clearable style="width: 200px" />-->
        </el-form-item>
        <el-form-item label="统计维度">
          <el-select v-model="searchParam.countType" placeholder="请选择统计维度"
                     style="width: 201px">
            <el-option v-for="item in countTypeList" :key="item.id" :label="item.name" :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item label="提报日期" prop="date">
          <el-date-picker
              v-model="searchParam.dateList"
              style="width: 250px"
              type="daterange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <!--        <el-form-item label="质检方案名称">-->
        <!--          <el-input v-model="searchParam.name" placeholder="请输入质检方案名称" clearable style="width: 200px"/>-->
        <!--        </el-form-item>-->
        <el-row style="display: flex;justify-content: flex-end">
          <el-form-item>
            <el-button type="primary" :icon="Search" @click="handleSearch()">查询</el-button>
            <el-button :icon="Refresh" @click="resetSearch()">重置</el-button>
          </el-form-item>
        </el-row>

      </el-form>
    </el-tabs>

    <div class="pageTableView">
      <div class="pageTableMenuView">
        <div class="pageTableTitle">列表信息</div>
        <div class="pageTableButView">
          <el-button :icon="Download" :loading="downLoading" @click="handleExport">导出</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <el-table class="pageTableClass" :data="paginatedData" border show-summary
                :summary-method="getSummaries" height="calc(100vh - 700px)">
        <el-table-column label="序号" type="index" align="center" width="70"/>
        <el-table-column prop="data" label="日期" align="center" min-width="200"/>
        <el-table-column prop="factoryName" label="工厂" align="center" min-width="200"/>
        <el-table-column prop="organizationName" label="车间" align="center" min-width="200"
                         v-if="activeName!=='first'"/>
        <el-table-column prop="materialNo" label="产品编码" align="center" min-width="200" v-if="activeName ==='third'"/>
        <el-table-column prop="reportCount" label="报工数量" align="center" min-width="200"/>
        <el-table-column prop="batchCount" label="批次总数量" align="center" min-width="200"/>
        <el-table-column prop="batchPassCount" label="批次合格数量" align="center" min-width="200"/>
        <el-table-column prop="batchPassRate" label="批次合格率" align="center" min-width="200">
          <template #default="scope">
            <div v-if="scope.row.batchPassRate">{{ scope.row.batchPassRate }}%</div>
            <div v-else></div>
          </template>
        </el-table-column>
        <el-table-column prop="passRate" label="良品率" align="center" min-width="200">
          <template #default="scope">
            <div v-if="scope.row.passRate">{{ scope.row.passRate }}%</div>
            <div v-else></div>
          </template>
        </el-table-column>
        <el-table-column prop="failQuantity" label="不合格数量" align="center" min-width="100"/>
        <el-table-column prop="failRate" label="不合格率" align="center" min-width="200">
          <template #default="scope">
            <div v-if="scope.row.failRate">{{ scope.row.failRate }}%</div>
            <div v-else></div>
          </template>
        </el-table-column>
        <!--        <el-table-column prop="batchTotalQuantity" label="不良率" align="center" min-width="110">-->
        <!--          <template #default="scope">-->
        <!--            <div v-if="scope.row.batchTotalQuantity">{{ scope.row.batchTotalQuantity }}%</div>-->
        <!--            <div v-else></div>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column prop="scrapQuantity" label="报废数量" align="center" min-width="110"/>
        <el-table-column prop="scrapRate" label="报废率" align="center" min-width="100">
          <template #default="scope">
            <div v-if="scope.row.scrapRate">{{ scope.row.scrapRate }}%</div>
            <div v-else></div>
          </template>
        </el-table-column>
        <el-table-column prop="dppm" label="DPPM" align="center" min-width="110"/>

        <!--				<el-table-column prop="unQualifiedQuantity" label="NCR数量" align="center"-->
        <!--												 min-width="100" />-->
        <!--				<el-table-column prop="createTime" label="DPPM" align="center" min-width="200" />-->


        <!--        <el-table-column prop="statusShow" label="质检" align="center" min-width="200">-->
        <!--          <template #default="scope">-->
        <!--            <div v-if="scope.row.statusShow">已完结</div>-->
        <!--            <div v-else>未完结</div>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--				<el-table-column label="操作" align="center" fixed="right" width="120">-->
        <!--					<template #default="scope">-->
        <!--						<el-button @click="handleConfigEdit(scope.row)" size="small" type="text" :icon="Edit"> 详情-->
        <!--						</el-button>-->
        <!--						            <el-button @click="handleConfigEdit(scope.row)" :disabled="scope.row.statusShow" type="warning" size="small"-->
        <!--						                       plain :icon="DocumentCopy">结果录入-->
        <!--						            </el-button>-->
        <!--						            <el-button @click="handleDel(scope.row)" :disabled="scope.row.statusShow" type="danger" size="small" plain-->
        <!--						                       :icon="Delete">删除-->
        <!--						            </el-button>-->
        <!--					</template>-->
        <!--				</el-table-column>-->
      </el-table>
      <!--			<div class="pagePagination">-->
      <!--				<el-pagination background v-model:current-page="pageSearch.current"-->
      <!--											 v-model:page-size="pageSearch.pageSize" :page-sizes="[10, 20, 50, 100, 200, 500]"-->
      <!--											 layout="total, sizes, prev, pager, next" :total="pageTotal" @size-change="handleSizeChange"-->
      <!--											 @current-change="handleCurrentChange" />-->
      <!--			</div>-->
    </div>


    <div class="pageTableView">
      <div class="pageTableMenuView">
        <div class="pageTableTitle">良率</div>
        <div class="pageTableButView">
        </div>
      </div>
      <div ref="OEELineChart" id="OEELineChart" style="width: 100%;height:240px">
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import axiosInstance from '@/utils/http/api';
import type {FormInstance, FormRules} from 'element-plus';
import {ElMessage, ElMessageBox} from 'element-plus';
import {
  Delete, Edit, Tickets, DocumentChecked
  , Search, Share, Upload, Refresh, Plus, DocumentCopy, Files, Download
} from '@element-plus/icons-vue';
import {computed, reactive, ref} from 'vue';
import * as echarts from 'echarts';
import axios from 'axios';
import moment from 'moment';
import {Decimal} from 'decimal.js';

onMounted(() => {
  // handleSearch();
  // getMaterial()
  getQualityPlanList();
  setOEELineChart();
});

const getSummaries = (param) => {
  const {columns, data} = param;
  const sums = [];
  const totals = {
    reportCount: 0,
    batchCount: 0,
    batchPassCount: 0,
    failQuantity: 0,
    scrapQuantity: 0,
    qualitySchemeTaskFailCount: 0
  };

  // 计算合计值
  data.forEach(item => {
    totals.reportCount += item.reportCount || 0;
    totals.batchCount += item.batchCount || 0;
    totals.batchPassCount += item.batchPassCount || 0;
    totals.failQuantity += item.failQuantity || 0;
    totals.scrapQuantity += item.scrapQuantity || 0;
    totals.qualitySchemeTaskFailCount += item.qualitySchemeTaskFailCount || 0;

  });

  console.log(totals, 'totals')

  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '合计';
      return;
    }

    // 百分比字段的特殊处理
    if (column.property === 'batchPassRate') {
      sums[index] = totals.batchCount > 0
          ? (totals.batchPassCount / totals.batchCount * 100).toFixed(2) + '%'
          : '0%';
    } else if (column.property === 'passRate') {
      sums[index] = totals.reportCount > 0
          ? (100 - (totals.failQuantity / totals.reportCount * 100)).toFixed(2) + '%'
          : '100%';
    } else if (column.property === 'failRate') {
      sums[index] = totals.reportCount > 0
          ? (totals.failQuantity / totals.reportCount * 100).toFixed(2) + '%'
          : '0%';
    } else if (column.property === 'scrapRate') {
      sums[index] = totals.reportCount > 0
          ? (totals.scrapQuantity / totals.reportCount * 100).toFixed(2) + '%'
          : '0%';
    } else if (column.property === 'dppm') {
      if (totals.reportCount > 0) {
        const ratio = (totals.qualitySchemeTaskFailCount / totals.reportCount).toFixed(7); // 保留七位小数
        sums[index] = Math.round(parseFloat(ratio) * 1e6); // 乘以1,000,000后四舍五入取整
      } else {
        sums[index] = '0';
      }
    }
    // 其他数值字段合计
    else if (['reportCount', 'batchCount', 'batchPassCount', 'failQuantity', 'scrapQuantity'].includes(column.property)) {
      sums[index] = data.reduce((sum, item) => sum + (item[column.property] || 0), 0);
    }
  });
  return sums;
};

const OEELineChart = ref(null);

const setOEELineChart = () => {
  if (!OEELineChart.value) return;
  const myChart = echarts.init(OEELineChart.value);
  myChart.setOption({
    backgroundColor: '#FFF',
    grid: {
      top: '15%',
      bottom: '20%',
      left: '3%',
      right: '0%'
    },
    tooltip: {
      trigger: 'axis',
      formatter: function (params) {
        return params[0].value + '%';
      }
    },
    xAxis: {
      boundaryGap: true,
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false,
        alignWithLabel: true
      },
      data: xLabel.value
    },
    yAxis: {
      axisLine: {
        show: false
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dashed',
          color: 'rgba(33,148,246,0.2)'
        }
      },
      axisTick: {
        show: false
      },
      splitArea: {
        show: true,
        areaStyle: {
          color: 'rgb(245,250,254)'
        }
      },
      axisLabel: {
        formatter: '{value}%'
      }
    },
    series: [
      {
        type: 'line',
        symbol: 'circle',
        symbolSize: 7,
        lineStyle: {
          color: 'rgb(33,148,246)',
          shadowBlur: 12,
          shadowColor: 'rgb(33,148,246,0.9)',
          shadowOffsetX: 1,
          shadowOffsetY: 1
        },
        itemStyle: {
          color: 'rgb(33,148,246)',
          borderWidth: 1,
          borderColor: '#FFF'
        },
        label: {
          show: true,
          position: 'top',
          distance: 5,
          color: '#333',
          fontSize: 12,
          formatter: '{c}%'
        },
        emphasis: {
          label: {
            show: true,
            color: '#333',
            fontSize: 14
          }
        },
        data: dataLabel.value
      }
    ]
  });
};

const xLabel = ref([]);
const dataLabel = ref([]);
const qualityPlanList = ref({});
const countTypeList = ref([{id: 1, name: '年'}, {id: 2, name: '月'}, {id: 3, name: '日'}]);
const OEELineChartParam = ref();
const factoryList = ref([]);
const workShopList = ref([]);
const getQualityPlanList = () => {
  axiosInstance.post('/api/basedataOrganization/getAll', {})
      .then(res => {
        if (res.code !== 200) {
          ElMessage.error(res.message);
          return false;
        }
        factoryList.value = res.data;
        searchParam.value.factoryId = res.data[0].id;
        workShopList.value = res.data[0].sonList;
        // handleSearch();
      });

  axiosInstance.post('/api/basedataMaterial/getPage', {current: 1, pageSize: 20})
      .then(res => {
        if (res.code !== 200) {
          ElMessage.error(res.message);
          return false;
        }
        materialList.value = res.data.records;
        // handleSearch();
      });
};


const pageSearch = ref({
  current: 1,
  pageSize: 999
});

const schemeTaskForm = ref({});

const configTableShow = ref(false);


const handleClick = (tab: TabsPaneContext, event: Event) => {
  activeName.value = tab.paneName;
  searchParam.value.organizationIds = [];
  searchParam.value.organizationId = null;
  console.log(activeName.value);
};
// 配置质检项表
const configTable = ref([]);

// 可适用物料
const materialTable = ref([]);


const rowInfo = ref({});
// 点击配置质检项表
const handleConfigEdit = (e) => {
  const row = JSON.parse(JSON.stringify(e));
  rowInfo.value = row;
  const list = JSON.parse(row.qualityJson);
  schemeTaskForm.value = list.schemeTaskForm ? list.schemeTaskForm : [];
  configTable.value = list.configTable ? list.configTable : [];
  const param = JSON.parse(row.qualityJson);
  const loop = {...param, ...row};
  Object.assign(formData, loop);
  isEdit.value = true;
  configTableShow.value = true;
};

const materialList = ref([]);

const materialData = ref({});
const showMaterial = ref(false);
// 质检列表
const isConfigEdit = ref(false);

const isConfigIndex = ref(null);


const activeName = ref('first');

const getMaterialList = (e) => {
  if (e) {
    axiosInstance.post('/api/basedataMaterial/getPage', {
      current: 1,
      pageSize: 20,
      materialName: e
    }).then(res => {
      materialList.value = res.data.records
    })
  }
}


const getQualityPlan = (e) => {
  let name = '';
  qualityPlanList.value.forEach(item => {
    if (item.id == e) {
      name = item.name;
    }
  });
  return name;
};

const getQualityWay = (e) => {
  let name = '';
  qualityWayList.value.forEach(item => {
    if (item.value == e) {
      name = item.label;
    }
  });
  return name;
};

const getQualityTypeList = (e) => {
  let name = '';
  qualityTypeList.value.forEach(item => {
    if (item.value == e) {
      name = item.label;
    }
  });
  return name;
};


// 通用更新接口函数
const handleUpdateQualityScheme = (updatedRowInfo) => {
  axiosInstance.put('/api/basedataQualityScheme/update', updatedRowInfo).then(res => {
    if (res.code != 200) {
      ElMessage.error(res.message);
      return false;
    }
    ElMessage.success('操作成功!');
    // showConfig.value = false;
    // showMaterial.value = false
    configTableShow.value = false;
    // 刷新配置质检项列表
    // handleConfigEdit(rowInfo.value);
    handleSearch();
  });
};


const materialId = ref(null);

// 质检项表删除 新建 编辑
const handleSaveConfig = () => {
  const jsonParam = JSON.parse(rowInfo.value.qualityJson);
  if (!schemeTaskForm.value.qualifiedQuantity) {
    ElMessage.error('请输入合格数量');
    return false;
  }
  if (!schemeTaskForm.value.unQualifiedQuantity) {
    ElMessage.error('请输入不合格数量');
    return false;
  }
  if (!schemeTaskForm.value.schemeTaskRemark) {
    ElMessage.error('请输入不良原因');
    return false;
  }
  jsonParam.schemeTaskForm = schemeTaskForm.value;
  jsonParam.configTable = configTable.value;
  rowInfo.value.status = true;
  delete jsonParam.qualityJson;
  rowInfo.value.qualityJson = JSON.stringify(jsonParam);
  handleUpdateQualityScheme(rowInfo.value);
};


const pageTotal = ref(null);//页面总数
// const formData = reactive({});//form表单
const isEdit = ref(false); // 是否编辑
const showCrud = ref(false); // 编辑/新建弹框
const searchParam = ref({
  countType: 3,
  dateList: [moment().subtract(6, 'days').format('YYYY-MM-DD'), // 7天前（含今天）
    moment().format('YYYY-MM-DD')]
});//页面检索条件
const showConfig = ref(false);
const configData = ref({});
const crudTitle = computed(() => {
  return isEdit.value ? '编辑' : '新建';
});//弹出层标题

// 质检方式
const qualityWayList = ref([
  {
    label: '全检',
    value: '1'
  }, {
    label: '比例抽检',
    value: '2'
  }, {
    label: '固定抽检',
    value: '3'
  }, {
    label: '自定义抽检',
    value: '4'
  }
]);


// 判断质检类型
const getQualityTypeByValue = (e) => {
  let name = null;
  for (const item of qualityTypeList.value) {
    if (e == item.value) {
      name = item.label;
    }
  }
  return name;
};

// 质检类型
const qualityTypeList = ref([
  {
    label: '首件检',
    value: '1',
    type: 'material'
  },
  {
    label: '末件检',
    value: '2',
    type: 'material'
  },
  {
    label: '生产',
    value: '3',
    type: 'material'
  },
  {
    label: '巡检',
    value: '4',
    type: 'material'
  },
  {
    label: '入库检',
    value: '5',
    type: 'procedure'
  },
  {
    label: '出库检',
    value: '6',
    type: 'procedure'
  },
  {
    label: '来料检',
    value: '7',
    type: 'procedure'
  }
  // 继续添加更多检查类型...
]);

const ruleFormRef = ref<FormInstance>();

interface RuleForm {
  name: string;
  code: string;
  qualityWay: string;
  proportionNumber: string;
  qualityNumber: string;
  qualityType: string;
  qualityInterval: number;
  qualityIsLive: boolean;
  qualityRemark: string;
  qualityJson: string;
}


const originalFormData = reactive<RuleForm>({
  name: '',
  code: '',
  qualityWay: null,
  proportionNumber: 1,
  qualityNumber: 1,
  qualityType: '',
  qualityInterval: 1,
  qualityIsLive: true,
  qualityRemark: '',
  qualityJson: null
});

let formData = reactive<RuleForm>(originalFormData);


const rules = reactive<FormRules<formData>>({
  sourceNo: [
    {required: true, message: '请输入来源单号', trigger: 'blur'}
  ],
  qualityPlan: [
    {required: true, message: '请选择质检方案', trigger: 'blur'}
  ],
  samplingMethod: [
    {required: true, message: '请选择质检方式', trigger: 'blur'}
  ]
});


// const paginatedData = reactive([])//列表数据
const paginatedData = ref<RuleForm[]>([]);

const downLoading = ref(false);
const handleExport = () => {
  let param = JSON.parse(JSON.stringify(searchParam.value));
  if (param.dateList) {
    param.startDateTime = param.dateList[0] + ' 00:00:00';
    param.endDateTime = param.dateList[1] + ' 23:59:59';
  } else {
    ElMessage.error('请选择日期');
    return false;
  }
  downLoading.value = true;

  switch (activeName.value) {
    case 'first':
      param.selectType = 1;
      break;
    case 'second':
      param.selectType = 2;
      break;
    case 'third':
      param.selectType = 3;
      break;
    default:
      param.selectType = 1;
      break;
  }
  axios.post('/api/reportWorkRecord/exportQualityComprehensive ', param, {
    timeout: 30000, // 与 axiosInstance 的 timeout 相同
    responseType: 'blob',
    headers: {
      BearerToken: localStorage.getItem('token') || undefined // 与请求拦截器中的设置相同
    }
  })
      .then(response => {
        console.log(response);
        const url = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', '库存详情.xlsx'); // 导出的格式一定要和接口返回的文件一致
        document.body.appendChild(link);
        link.click();
        window.URL.revokeObjectURL(url);
        document.body.removeChild(link);
      })
      .finally(() => {
        downLoading.value = false;
      });
};


// 获取列表接口
const handleSearch = () => {
  let param = JSON.parse(JSON.stringify(searchParam.value));
  if (param.dateList) {
    param.startDateTime = param.dateList[0] + ' 00:00:00';
    param.endDateTime = param.dateList[1] + ' 23:59:59';
  } else {
    ElMessage.error('请选择日期');
    return false;
  }

  switch (activeName.value) {
    case 'first':
      param.selectType = 1;
      break;
    case 'second':
      param.selectType = 2;
      break;
    case 'third':
      param.selectType = 3;
      break;
    default:
      param.selectType = 1;
      break;
  }
  axiosInstance.post('/api/reportWorkRecord/qualityComprehensive', {...param, ...searchParam.value})
      .then(res => {
        if (res.code !== 200) {
          ElMessage.error(res.message);
          return false;
        }

        paginatedData.value = res.data;

        setDataV();
      });
};
const setDataV = () => {
  const list = JSON.parse(JSON.stringify(paginatedData.value));
// 根据 passRate 排序，并取前七条最高的记录
  const sortedList = list.sort((a, b) => b.passRate - a.passRate).slice(0, 7);
  const infoList = sortedList.sort((a, b) => a.passRate - b.passRate);
  console.log(infoList); // 打印排序后取前七条记录的数组
  dataLabel.value = infoList.map(item => item.passRate);

  switch (activeName.value) {
    case 'first':
      xLabel.value = infoList.map(item => item.data);
      break;
    case 'second':
      xLabel.value = infoList.map(item => item.organizationName);
      break;
    case 'third':
      xLabel.value = infoList.map(item => item.materialNo);
      break;
    default:
      xLabel.value = infoList.map(item => item.data);
      break;
  }
  setOEELineChart();
};
const handleSizeChange = (e) => {
  pageSearch.value.pageSize = e;
  handleSearch();
};

const handleCurrentChange = (e) => {
  pageSearch.value.current = e;
  handleSearch();
};

// 重置搜索条件
const resetSearch = () => {
  searchParam.value = {
    factoryId: factoryList.value[0].id,
    countType: 1
  };
  pageSearch.value.current = 1;
  // current.value = 1
  // handleSearch();
};

// 点击新建
const handleAdd = () => {
  isEdit.value = false;
  // ruleFormRef.value.resetFields()
  formData = reactive({});
  showCrud.value = true;
};

// 编辑
const handleEdit = (row: any) => {
  isEdit.value = true;
  const param = JSON.parse(row.qualityJson);
  const list = {...param, ...row};
  Object.assign(formData, list);
  showCrud.value = true;
};

// 删除记录
const handleDel = (row: any) => {
  ElMessageBox.confirm('确定删除该条记录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    axiosInstance.delete(`/api/qualitySchemeTask/delete`, {
      data: {
        ids: [row.id]
      }
    }).then(res => {
      ElMessage.success('删除成功');
      handleSearch(); // 刷新数据
    });


  });
};


// 弹框确定 确认新建 确定编辑
const handleSave = async (e: FormInstance | undefined) => {
  if (!e) return;
  await e.validate((valid, fields) => {
    if (valid) {
      const jsonString = JSON.stringify(formData);
      formData.qualityJson = jsonString;
      if (isEdit.value) {
        // 编辑
        axiosInstance.put('/api/qualitySchemeTask/update', formData).then(res => {
          if (res.code != 200) {
            ElMessage.error(res.message);
            return false;
          }
          ElMessage.success('操作成功!');
          showCrud.value = false;
          handleSearch(); // 刷新数据
        });
      } else {
        // 新建
        const paramData = formData;
        paramData.id = null;
        paramData.status = false;
        axiosInstance.post('/api/qualitySchemeTask/save', paramData).then(res => {
          if (res.code != 200) {
            ElMessage.error(res.message);
            return false;
          }
          ElMessage.success('操作成功!');
          showCrud.value = false;
          handleSearch(); // 刷新数据
        });
      }

    }
  });
};
</script>
<style scoped>
.content {
  /*padding: 20px;*/
}
</style>
